﻿using APIShoppingSystem.Model;
using IShoppingBll;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace APIShoppingSystem.Controllers
{
	[Route("api/[controller]/[action]")]
	[ApiController]
	public class SalesrRecordController : ControllerBase
	{
        private ISalesrRecordBll _salesrRecordBll;
        private IOrderInfoBll _orderInfoBll;
        private ICommodityInfoBll _commodityInfoBll;
        private IReturnsBll _returnsBll;

        public SalesrRecordController(ISalesrRecordBll salesrRecordBll, IOrderInfoBll orderInfoBll, ICommodityInfoBll commodityInfoBll, IReturnsBll returnsBll)
        {
            _salesrRecordBll = salesrRecordBll;
            _orderInfoBll = orderInfoBll;
            _commodityInfoBll = commodityInfoBll;
            _returnsBll = returnsBll;
        }


        /// <summary>
        /// 获取商品统计展示分页
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult SalesrRecordPageList(int page, int limit, string commodityName)
        {
            CustomActionResult res = new CustomActionResult();
            int count;
            object shoppingStatistics = _salesrRecordBll.GetSalesrRecordPageList(page, limit, out count, commodityName);

            return new JsonResult(new
            {
                code = 0,
                msg = "成功",
                count = count,
                data = shoppingStatistics
            });


        }


        /// <summary>
        /// 获取商品名字、数量
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetSalesrRecord()
        {
            CustomActionResult res = new CustomActionResult();

            var getSR = _salesrRecordBll.GetSalesrRecord();
            res.Status = 1;
            res.IsSuccess = true;
            res.Msg = "成功";
            res.Datas = getSR;
            return new JsonResult(res);

        }


        /// <summary>
        /// 获取退货商品的名字、数量
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetReturnRecord()
        {
            CustomActionResult res = new CustomActionResult();

            var getSR = _salesrRecordBll.GetReturnRecord();
            res.Status = 1;
            res.IsSuccess = true;
            res.Msg = "成功";
            res.Datas = getSR;
            return new JsonResult(res);
        }
    }
}
